/*
 * BBActionNewTower.java
 *
 * Created on March 10, 2008, 7:08 PM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */
package hextd.blackBox;

import hextd.tower.TowerFactory;
import hextd.core.Context;
import hextd.message.MessageTowerBuy;

/**
 *
 * @author hylke
 */
public class BBActionNewTower implements BBAction {

	private static final BlackBox.ActionType type = BlackBox.ActionType.NewTower;
	private int gameTime;
	private int activateTick;
	private int row;
	private int col;
	private int owner;
	private TowerFactory.type ttype;

	/** Creates a new instance of BBActionNewTower */
	public BBActionNewTower(int gameTime, int row, int col, TowerFactory.type t, int owner, int activateTick) {
		this.gameTime = gameTime;
		this.row = row;
		this.col = col;
		this.ttype = t;
		this.owner = owner;
		this.activateTick = activateTick;
	}

	@Override
	public BlackBox.ActionType getType() {
		return BBActionNewTower.type;
	}

	@Override
	public int getGameTime() {
		return this.gameTime;
	}

	@Override
	public void execute(Context c) {
		//System.out.println("BBActionNewTower::execute: "+c.gameTime+" Building Tower "+this.ttype.toString()+".");
		if (!c.getBlackBox().newTower(gameTime, this.col, this.row, this.ttype, owner, this.activateTick, false)) {
			System.err.println("BBActionNewTower::execute: " + gameTime + " Sync error: Tower build failed!");
			System.err.println("    user:" + owner + " col:" + col + " row:" + row + " type:" + ttype + " activateAt:" + activateTick);
		}
	}

	@Override
	public String getString() {
		return MessageTowerBuy.formatMessage(owner, gameTime, row, col, ttype);
	}
}
